package forms;

import javax.servlet.http.HttpServletRequest;

import model.StudentDBModel;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

public class ReviewersForm extends ActionForm {
	
	private static final long serialVersionUID = 4L;
	
	private String score;
	
	private enum Mappings{
		FEEDBACK,
		DEFAULT
	}
	
	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {
		

		
		ActionErrors errors = new ActionErrors();
		Mappings currentMapping = Mappings.DEFAULT;
		
		if(mapping.getPath().equals("/pages/reviewers/SubmitFeedback")){
			currentMapping = Mappings.FEEDBACK;			
		}
		
		
		switch(currentMapping)
		{
		
		case FEEDBACK:
		{
			if(score == null)
			{
				errors.add("noScore", new ActionMessage("errors.noscore"));
			}
			else if( !validScore(score))
			{
				errors.add("onedigit", new ActionMessage("errors.invalidscore"));
			}
			break;
		}
		default:
		{
			
			break;
		}
		
		
		}
		
		return errors;
	}
	
	public static boolean
	validScore( String str ){
		if( (str == null) || (str.length() != 1)) return false;
		
		if( !Character.isDigit(str.charAt(0))){ 
				return false;
			
		}
		if((Integer.valueOf(str) > 0) && (Integer.valueOf(str) < 5))
		{
			return true;
		}
		return false;
	}

	public String getScore() {
		return score;
	}

	public void setScore(String score) {
		this.score = score;
	}

}
